import React, { useEffect, useCallback, useState }  from 'react';
import { postSofBillingRegisterAccount } from '../../../../api'
import { getSysMarkFindMark } from '../../../../../../Api/communalUrl';
import { Modal, Form, InputNumber, Select, DatePicker, message } from 'antd'
import moment from 'moment'

const { Option } = Select;

/**
 * @description: 实收、应收  操作-》登记到账弹窗
 * @author: xiaoxujs
 * @updata: xiaoxujs（2021-11-20）收款方式内容改变：1.银行转账2.银行承兑3.商业承兑4.现金5.信用票据 是否开发票拉出来单独一页二级页面，名称为开票登记
 */

const AddRegisterMoneyModule = ({ setAddRegisterMoneyModuleShow, addRegisterMoneyModuleShow, billId, conNo, listFun }) => {
    const [form] = Form.useForm()
    const { validateFields, resetFields } = form;
    const [typeData, setTypeData] = useState([]);
    const typeFun = useCallback(
        () => {
            // 收款方式(SKFS)
            ; (async () => {
                const { code, msg, data } = await getSysMarkFindMark({ typeCode: 'SKFS' })
                if (code === '20000') {
                    setTypeData(data)
                } else {
                    message.error(msg)
                }
            })();
        },
        [],
    );
    useEffect(() => {
        typeFun();
    }, [typeFun])
    const handleOk = () => {
        validateFields().then(values => {
            if (values.fapiao) {
                values.invoiceTime = moment(values.invoiceTime).format("YYYY-MM-DD")
                values.invoice = {
                    invoiceKind: values.invoiceKind,
                    invoiceMoney: values.invoiceMoney,
                    invoiceNo: values.invoiceNo,
                    invoiceTime: values.invoiceTime,
                    invoiceTitle: values.invoiceTitle,
                }
            }
            values.actAccountsDate = moment(values.actAccountsDate).format("YYYY-MM-DD")

            values.billId = billId
            values.conNo = conNo

            delete values.invoiceKind
            delete values.invoiceMoney
            delete values.invoiceNo
            delete values.invoiceTime
            delete values.invoiceTitle
            delete values.fapiao
                ; (async () => {
                    const { code, msg } = await postSofBillingRegisterAccount(values)
                    if (code === '20000') {
                        message.success('登记到账添加成功！')
                        listFun()
                        resetFields()
                        setAddRegisterMoneyModuleShow(false);
                    } else {
                        message.error(msg)
                    }
                })()
        })
        // setAddRegisterMoneyModuleShow(false);
    };

    const handleCancel = () => {
        resetFields()
        setAddRegisterMoneyModuleShow(false);
    };
    return <Modal title="登记到账" visible={addRegisterMoneyModuleShow} onOk={handleOk} onCancel={handleCancel}>
        <Form
            name="basic"
            labelCol={{ span: 10 }}
            wrapperCol={{ span: 14 }}
            form={form}
        >
            <Form.Item
                label="到账金额"
                name="actAccounts"
                rules={[{ required: true, message: '请输入到账金额' }]}
            >
                <InputNumber />
            </Form.Item>
            <Form.Item
                label="到账日期"
                name="actAccountsDate"
                rules={[{ required: true, message: '请选择到账时间' }]}
            >
                <DatePicker />
            </Form.Item>
            <Form.Item
                label="收款方式"
                name="paymentTerm"
                rules={[{ required: true, message: '请选择有收款方式' }]}
            >
                {/* 1.银行转账2.银行承兑3.商业承兑4.现金5.信用票据  */}
                <Select >
                    {
                        typeData.map(item => <Option value={item.markValue} key={item.markValue}>{item.markName}</Option>)
                    }
                </Select>
            </Form.Item>
            {/* <Form.Item
                label="是否开发票"
                name="fapiao"
                rules={[{ required: true, message: '请选择是否开发票' }]}
            >
                <Radio.Group onChange={onChangeRadio} value={fapiaoShow}>
                    <Radio value={1}>开</Radio>
                    <Radio value={0}>不开</Radio>
                </Radio.Group>
            </Form.Item>
            {
                fapiaoShow ? <>
                    <Form.Item
                        label="发票号码"
                        name="invoiceNo"
                        rules={[{ required: true, message: '请输入发票号码' }]}
                    >
                        <Input />
                    </Form.Item>
                    <Form.Item
                        label="开票时间"
                        name="invoiceTime"
                        rules={[{ required: true, message: '请选择开票时间' }]}
                    >
                        <DatePicker />
                    </Form.Item>
                    <Form.Item
                        label="发票抬头"
                        name="invoiceTitle"
                        rules={[{ required: true, message: '请输入发票抬头' }]}
                    >
                        <Input />
                    </Form.Item>
                    <Form.Item
                        label="发票类型"
                        name="invoiceKind"
                        rules={[{ required: true, message: '请选择发票类型' }]}
                    >
                        <Select>
                            <Option value={0} >普通发票</Option>
                            <Option value={1} >增值税专用发票</Option>
                        </Select>
                    </Form.Item>
                    <Form.Item
                        label="开票金额"
                        name="invoiceMoney"
                        rules={[{ required: true, message: '请输入开票金额' }]}
                    >
                        <InputNumber />
                    </Form.Item>
                </> : null
            } */}
        </Form>
    </Modal>
}

export default AddRegisterMoneyModule